

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/blog/img/fluid.png">
  <link rel="icon" href="/blog/images/base.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Airfe">
  <meta name="keywords" content="">
  
    <meta name="description" content="本文将介绍HTML5的一些特性。">
<meta property="og:type" content="article">
<meta property="og:title" content="HTML5特性">
<meta property="og:url" content="https://airfe.gitee.io/blog/2023/04/12/HTML5%E7%89%B9%E6%80%A7/index.html">
<meta property="og:site_name" content="Airfe的博客">
<meta property="og:description" content="本文将介绍HTML5的一些特性。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/pageImage/HTML5%E7%89%B9%E6%80%A7.png">
<meta property="article:published_time" content="2023-04-12T00:00:00.000Z">
<meta property="article:modified_time" content="2024-02-26T12:20:17.695Z">
<meta property="article:author" content="Airfe">
<meta property="article:tag" content="html">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://markdown-1307246189.cos.ap-chongqing.myqcloud.com/pageImage/HTML5%E7%89%B9%E6%80%A7.png">
  
  
  
    <meta name="referrer" content="no-referrer" />
  
  <title>HTML5特性 - Airfe的博客</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"airfe.gitee.io","root":"/blog/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":"699a5d71ac7179b23874a59b0666a6f6","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"RW68dMkEpeIOJJiBr1lPkhOS-gzGzoHsz","app_key":"P5fzMTGSJIoTaGvmgzsUHeNZ","server_url":"https://rw68dmke.lc-cn-n1-shared.com","path":"window.location.pathname","ignore_local":false}},"search_path":"/blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/blog/js/utils.js" ></script>
  <script  src="/blog/js/color-schema.js" ></script>
  

  
    <!-- Baidu Analytics -->
    <script async>
      if (!Fluid.ctx.dnt) {
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "https://hm.baidu.com/hm.js?699a5d71ac7179b23874a59b0666a6f6";
          var s = document.getElementsByTagName("script")[0];
          s.parentNode.insertBefore(hm, s);
        })();
      }
    </script>
  

  

  

  

  

  

  
    
  



  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/blog/">
      <strong>Airfe</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/blog/images/bg.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="HTML5特性"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-04-12 08:00" pubdate>
          2023年04月12日
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          4.3k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          36 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">HTML5特性</h1>
            
            
              <div class="markdown-body">
                
                <h2 id="语义化标签"><a href="#语义化标签" class="headerlink" title="语义化标签"></a>语义化标签</h2><p>为了实现语义化标记，HTML 提供了明确这些区段的专用标签，例如：</p>
<ul>
<li><code>&lt;header&gt;</code>：页眉</li>
<li><code>&lt;nav&gt;</code>：导航栏</li>
<li><code>&lt;main&gt;</code>：主内容。主内容中还可以有各种子内容区段，可用<code>&lt;article&gt;</code>、<code>&lt;section&gt; </code>和<code>&lt;div&gt; </code>等元素表示。</li>
<li><code>&lt;aside&gt;</code>：侧边栏，经常嵌套在<code>&lt;main&gt;</code>中。</li>
<li><code>&lt;footer&gt;</code>：页脚。</li>
</ul>
<p>优势</p>
<ul>
<li>使界面的代码结构清晰，方便代码的阅读和团队的合作开发</li>
<li>方便其他设备解析（如屏幕阅读器、盲人阅读器、移动设备）以语义的方式来渲染网页。</li>
<li>有利于搜索引擎优化（<code>SEO</code>）。</li>
</ul>
<h2 id="多媒体标签"><a href="#多媒体标签" class="headerlink" title="多媒体标签"></a>多媒体标签</h2><ul>
<li><p>音频：<code>&lt;audio&gt;</code></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">audio</span> <span class="hljs-attr">src</span>= <span class="hljs-string">&quot;media/music.mp3&quot;</span> <span class="hljs-attr">autoplay</span>= <span class="hljs-string">&quot;autoplay&quot;</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">audio</span>&gt;</span><br></code></pre></td></tr></table></figure>

<blockquote>
<p>谷歌把自动播放音频和视频的功能关闭了，视频可以通过muted属性来静音播放视频，音频不可以（可以通过JavaScript解决）</p>
</blockquote>
</li>
<li><p>视频：<code>&lt;video&gt;</code></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">video</span> <span class="hljs-attr">src</span>= <span class="hljs-string">&quot;media/mi.mp4&quot;</span> <span class="hljs-attr">autoplay</span>= <span class="hljs-string">&quot;autoplay&quot;</span> <span class="hljs-attr">muted</span>= <span class="hljs-string">”muted</span>&quot;&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">video</span>&gt;</span><br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id="新增的input类型"><a href="#新增的input类型" class="headerlink" title="新增的input类型"></a>新增的input类型</h2><table>
<thead>
<tr>
<th>属性值</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>type&#x3D;”email”</td>
<td>限制用户输入必须为Email类型</td>
</tr>
<tr>
<td>type&#x3D;”url”</td>
<td>限制用户输入必须为URL类型</td>
</tr>
<tr>
<td>type&#x3D;”date”</td>
<td>限制用户输入必须为日期类型</td>
</tr>
<tr>
<td>type&#x3D;”time”</td>
<td>限制用户输入必须为时间类型</td>
</tr>
<tr>
<td>type&#x3D;”month”</td>
<td>限制用户输入必须为月类型</td>
</tr>
<tr>
<td>type&#x3D;”week”</td>
<td>限制用户输入必须为周类型</td>
</tr>
<tr>
<td>type&#x3D;”number”</td>
<td>限制用户输入必须为数字类型</td>
</tr>
<tr>
<td>type&#x3D;”tel”</td>
<td>手机号码</td>
</tr>
<tr>
<td>type&#x3D;”search”</td>
<td>搜索框</td>
</tr>
<tr>
<td>type&#x3D;”color”</td>
<td>生成一个颜色选择表单</td>
</tr>
</tbody></table>
<h2 id="新增的表单属性"><a href="#新增的表单属性" class="headerlink" title="新增的表单属性"></a>新增的表单属性</h2><table>
<thead>
<tr>
<th>属性</th>
<th><strong>描述</strong></th>
</tr>
</thead>
<tbody><tr>
<td>placehoder</td>
<td>输入框默认提示文字</td>
</tr>
<tr>
<td>required</td>
<td>要求输入的内容是否可为空</td>
</tr>
<tr>
<td>pattern</td>
<td>描述一个正则表达式验证输入的值</td>
</tr>
<tr>
<td>min&#x2F;max</td>
<td>设置元素最小&#x2F;最大值</td>
</tr>
<tr>
<td>step</td>
<td>为输入域规定合法的数字间隔</td>
</tr>
<tr>
<td>height&#x2F;wdith</td>
<td>用于image类型<code>&lt;input&gt;</code>标签图像高度&#x2F;宽度</td>
</tr>
<tr>
<td>autofocus</td>
<td>规定在页面加载时，域自动获得焦点</td>
</tr>
<tr>
<td>multiple</td>
<td>规定<code>&lt;input&gt;</code>元素中可选择多个值</td>
</tr>
</tbody></table>
<h2 id="Canvas绘图"><a href="#Canvas绘图" class="headerlink" title="Canvas绘图"></a>Canvas绘图</h2><p><code>canvas</code>就是画布，可以画线，图形，填充，图像绘制等操作。</p>
<p><code>Canvas</code>元素的定义</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs html">// 基本语法：在使用canvas时需要设定一个高度跟宽度将画布定下<br>// 文中的信息为浏览器不支持canvas标签时显示的文字<br><span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;drawing&quot;</span> <span class="hljs-attr">width</span>=<span class="hljs-string">&quot; 200&quot;</span> <span class="hljs-attr">height</span>=<span class="hljs-string">&quot;200&quot;</span>&gt;</span>A drawing of something.<span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span><br></code></pre></td></tr></table></figure>

<ul>
<li><code>id</code> 是<code>canvas</code>元素的标识；</li>
<li><code>height</code>是<code>canvas</code>画布的高度，单位为像素；</li>
<li><code>width</code>是<code>canvas</code>画布的宽度，单位为像素。</li>
</ul>
<p>使用<code>JavaScript</code>获取网页中的<code>Canvas</code>对象</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-comment">// 获取对象</span></span><br><span class="language-javascript">    <span class="hljs-keyword">var</span> drawing  = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">&#x27;drawing&#x27;</span>);</span><br><span class="language-javascript">    <span class="hljs-comment">// 获取drawing对象的2D绘图上下文</span></span><br><span class="language-javascript">	<span class="hljs-keyword">var</span> ctx = drawing.<span class="hljs-title function_">getContext</span>(‘2d’);</span><br><span class="language-javascript">    <span class="hljs-comment">// 开始绘制图像，可以是直线、矩形、圆弧</span></span><br><span class="language-javascript">    ...</span><br><span class="language-javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>（1）绘制直线</p>
<ul>
<li>调用<code>beginPath()</code>方法，指示开始绘图路径： <code>ctx.beginPath()</code>;</li>
<li>调用<code>moveTo()</code>方法将坐标移至直线起点： <code>ctx.moveTo(x,y)</code>;</li>
<li>调用<code>lineTo()</code>方法绘制直线： <code>ctx.lineTo(x,y)</code>，会改变当前点；</li>
<li>调用<code>stroke()</code>方法，绘制图形的边界轮廓： <code>ctx.stroke()</code>;</li>
<li>调用<code>closePath()</code>方法，闭合路径。拉一条从当前点到<code>path</code>起始点的直线。如果当前点与起始点重合，则什么都不做：<code>ctx.closePath()</code>;</li>
</ul>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-keyword">var</span> mycanvas=<span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">&quot;canvas&quot;</span>);</span><br><span class="language-javascript">    <span class="hljs-keyword">var</span> ctx=mycanvas.<span class="hljs-title function_">getContext</span>(<span class="hljs-string">&quot;2d&quot;</span>);</span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">beginPath</span>();</span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">moveTo</span>(<span class="hljs-number">100</span>,<span class="hljs-number">200</span>);</span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">lineTo</span>(<span class="hljs-number">400</span>,<span class="hljs-number">200</span>);</span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">lineTo</span>(<span class="hljs-number">250</span>,<span class="hljs-number">400</span>);</span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">closePath</span>();</span><br><span class="language-javascript">	ctx.<span class="hljs-property">strokeStyle</span>=<span class="hljs-string">&quot;#000000&quot;</span>;</span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">stroke</span>();</span><br><span class="language-javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>（2）绘制矩形</p>
<ul>
<li><p>绘制矩形：<code>rect(x,y,width,height)</code>； </p>
</li>
<li><p>绘制矩形边框：<code>strokeRect(x, y, width, height)</code>;</p>
</li>
<li><p>绘制填充矩形：<code>fillRect(x, y, width, height)</code>;</p>
</li>
<li><p>擦除指定矩形区域：<code>clearRect(x, y, width, height)</code>;</p>
</li>
</ul>
<blockquote>
<p>x：矩形左上角的X坐标</p>
<p>y：矩形左上角的y坐标</p>
<p>width：矩形的宽度</p>
<p>height：矩形的高度</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-keyword">var</span> mycanvas=<span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementById</span>(<span class="hljs-string">&quot;canvas&quot;</span>);</span><br><span class="language-javascript">	<span class="hljs-keyword">var</span> ctx=mycanvas.<span class="hljs-title function_">getContext</span>(<span class="hljs-string">&quot;2d&quot;</span>);</span><br><span class="language-javascript"> </span><br><span class="language-javascript">	<span class="hljs-comment">//rect()函数调用</span></span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">beginPath</span>();</span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">rect</span>(<span class="hljs-number">20</span>,<span class="hljs-number">20</span>,<span class="hljs-number">100</span>,<span class="hljs-number">50</span>);</span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">stroke</span>();</span><br><span class="language-javascript"> </span><br><span class="language-javascript">	<span class="hljs-comment">//strokeRect()函数调用</span></span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">strokeRect</span>(<span class="hljs-number">200</span>,<span class="hljs-number">20</span>,<span class="hljs-number">150</span>,<span class="hljs-number">60</span>);</span><br><span class="language-javascript"> </span><br><span class="language-javascript">	<span class="hljs-comment">//fillRect()函数调用</span></span><br><span class="language-javascript">	ctx.<span class="hljs-title function_">fillRect</span>(<span class="hljs-number">400</span>,<span class="hljs-number">20</span>,<span class="hljs-number">150</span>,<span class="hljs-number">60</span>);</span><br><span class="language-javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>注：<code>strokeRect()</code>方法与<code>rect()</code>方法的区别在于调用<code>strokeRect()</code>方法时不需要使用<code>beginPath()</code>和<code>stroke()</code>即可绘图。</p>
<p>（3）绘制圆弧</p>
<ul>
<li><code>arc(centerx,centery,radius,startAngle,endAngle,antiClockwise)</code>;<ul>
<li><code>centerx,centery</code>   圆弧中心点坐标</li>
<li><code>Radius</code> 半径</li>
<li><code>startAngle</code>  起始弧度</li>
<li><code>endAngle</code>  终止弧度</li>
<li><code>antiClockwise</code>  是否按逆时针方向绘图，   是一个可选参数，默认为<code>false</code>（即顺时针方向绘图）</li>
<li>弧度 &#x3D; 角度* ( <code>Math.PI / 180</code> )</li>
</ul>
</li>
</ul>
<p>（4）填充和描边</p>
<ul>
<li><p>描边</p>
<ul>
<li><code>strokeStyle</code>指定描边颜色（三种颜色方式均可）</li>
<li><code>lineWidth</code>指定描边宽度（像素为单位）</li>
</ul>
</li>
<li><p>填充</p>
<ul>
<li><code>fillStyle</code>指定填充颜色（三种颜色方式均可）</li>
</ul>
</li>
</ul>
<h2 id="应用缓存（Application-Cache）"><a href="#应用缓存（Application-Cache）" class="headerlink" title="应用缓存（Application Cache）"></a>应用缓存（Application Cache）</h2><p>在<code>HYML5</code>之前，我们需要接入网络才能访问，这毫无疑问是网站多次请求服务器，造成速度变慢。</p>
<p>实际开发中，主要是使用<code>Application Cache</code>和<code>LocalStorage</code>技术实现离线存储。</p>
<h3 id="Application-Cache"><a href="#Application-Cache" class="headerlink" title="Application Cache"></a>Application Cache</h3><p>通常用于静态资源（静态页面）的缓存。</p>
<p>涉及角色：服务器和<code>html</code>文件。</p>
<ul>
<li><p>服务器端：负责管理维护<code>manifest.appcache</code>文件。</p>
<ul>
<li><p><code>manifest</code> 文件可分为三个部分：</p>
<p><code>CACHE MANIFEST</code> - 在此标题下列出的文件将在首次下载后进行缓存(要缓存的文件)</p>
<p><code>NETWORK</code> - 在此标题下列出的文件需要与服务器连接，且不会被缓存（千万不要把首页<code>index</code>放入<code>NETWORK</code>中禁止缓存，否则插件等无法使用）</p>
<p><code>FALLBACK</code> - 在此标题下列出的文件规定当页面无法访问时的回退页面（比如 404 页面）</p>
</li>
</ul>
</li>
<li><p><code>Application Cache</code>生命销毁规则</p>
<ul>
<li><p>用户清空浏览器的缓存，此时<code>Application Cache</code>本地缓存将销毁。</p>
</li>
<li><p><code>manifest</code>文件被修改时，因为应用的缓存会在其 <code>manifest</code> 文件更改时被更新。如果您编辑了一幅图片，或者修改了一个 <code>JavaScript</code> 函数，这些改</p>
<p>变都不会被重新缓存，此时<code>Application Cache</code>本地缓存将销毁。</p>
</li>
<li><p>由程序来更新应用缓存</p>
</li>
</ul>
</li>
</ul>
<h2 id="本地存储"><a href="#本地存储" class="headerlink" title="本地存储"></a>本地存储</h2><p><code>Web Storage</code> 是<code>H5</code> 引入的一个帮助解决<code>cookie</code>存储本地缓存的重要功能。</p>
<blockquote>
<p>Webstorage 中有5M容量，cookie只有4k。</p>
</blockquote>
<h3 id="sessionStorage"><a href="#sessionStorage" class="headerlink" title="sessionStorage"></a>sessionStorage</h3><p><code>sessionStorage</code>将数据保存在<code>session</code>中，浏览器关闭数据就消失。</p>
<h3 id="localStorage"><a href="#localStorage" class="headerlink" title="localStorage"></a>localStorage</h3><p><code>localStorage</code>则一直将数据保存在客户端本地，除非手动删除，否则一直保存。</p>
<p>不管是<code>sessionStorage</code>，还是<code>localStorage</code>，可使用的<code>API</code>相同，常用的有如下几个（以<code>localStorage</code>为例）：</p>
<ul>
<li><p>保存数据：<code>localStorage.setItem(key,value)</code>;</p>
</li>
<li><p>读取数据：<code>localStorage.getItem(key)</code>;</p>
</li>
<li><p>删除单个数据：<code>localStorage.removeItem(key)</code>;</p>
</li>
<li><p>删除所有数据：<code>localStorage.clear()</code>;</p>
</li>
<li><p>得到某个索引的<code>key</code>：<code>localStorage.key(index)</code>;</p>
</li>
</ul>
<h2 id="WebSocket"><a href="#WebSocket" class="headerlink" title="WebSocket"></a>WebSocket</h2><ul>
<li><p>WebSocket协议为web应用程序客户端和服务端之间提供了一种全双工通信机制。</p>
</li>
<li><p>握手阶段采用HTTP协议，在服务端与客户端初次握手时，将HTTP协议升级成WebSocket协议当链接成功时就可以在双工模式下来回传递信息。</p>
</li>
<li><p>没有同源限制，客户端可以与任意服务器通信。</p>
</li>
<li><p>协议标识符为wx（如果加密为wxs）。</p>
</li>
<li><p>除了协议定义外还有JS定义，只需要链接远程主机，并建立一个WebSocket实例链接到对端的URL即可。</p>
</li>
</ul>
<h2 id="无障碍"><a href="#无障碍" class="headerlink" title="无障碍"></a>无障碍</h2><p>无障碍是一种让尽可能多的用户可以使用你的网站的做法。</p>
<p>只要确保恰当的 HTML 元素被用于适当的目的，大量的网页内容即可具有无障碍；当正确使用 CSS 与 JavaScript 的时候，也能够使得网</p>
<p>页具有很好的无障碍；可以提高无障碍的另一类内容是多媒体（视频，音频和图像）内容提供适当的文本替代方案，以便辅助技术和相应</p>
<p>的用户能够理解。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/blog/categories/%E5%89%8D%E7%AB%AF%E6%8A%80%E6%9C%AF%E6%A0%88/" class="category-chain-item">前端技术栈</a>
  
  
    <span>></span>
    
  <a href="/blog/categories/%E5%89%8D%E7%AB%AF%E6%8A%80%E6%9C%AF%E6%A0%88/html/" class="category-chain-item">html</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/blog/tags/html/">#html</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>HTML5特性</div>
      <div>https://airfe.gitee.io/blog/2023/04/12/HTML5特性/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Airfe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年4月12日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/blog/2023/04/13/%E5%8E%9F%E5%A7%8B%E5%80%BC%E5%92%8C%E5%BC%95%E7%94%A8%E5%80%BC%E6%A6%82%E6%8B%AC/" title="原始值和引用值概括">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">原始值和引用值概括</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/blog/2023/04/10/Webpack%EF%BC%88%E4%B8%80%EF%BC%89%E5%8E%9F%E7%90%86/" title="Webpack原理">
                        <span class="hidden-mobile">Webpack原理</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"RW68dMkEpeIOJJiBr1lPkhOS-gzGzoHsz","appKey":"P5fzMTGSJIoTaGvmgzsUHeNZ","path":"window.location.pathname","placeholder":"发表你的看法吧~","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":false,"appid":"RW68dMkEpeIOJJiBr1lPkhOS-gzGzoHsz","appkey":"P5fzMTGSJIoTaGvmgzsUHeNZ","server_url":"https://rw68dmke.lc-cn-n1-shared.com"},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
        <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> <div style="font-size: 0.85rem"> <span id="timeDate">载入天数</span> <span id="times">载入时分秒</span> <script src="js/duration.js"></script> </div> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="leancloud-site-pv-container" style="display: none">
        总访问量 
        <span id="leancloud-site-pv"></span>
         次
      </span>
    
    
      <span id="leancloud-site-uv-container" style="display: none">
        总访客数 
        <span id="leancloud-site-uv"></span>
         人
      </span>
    
    

  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      蜀ICP备2023008943号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=https://beian.miit.gov.cn/"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="" srcset="/blog/img/loading.gif" lazyload data-original="/blog/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/blog/js/events.js" ></script>
<script  src="/blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script defer src="/blog/js/leancloud.js" ></script>

  <script  src="/blog/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>

        <style>
            [bg-lazy] {
                background-image: none !important;
                background-color: #eee !important;
            }
        </style>
        <script>
            window.imageLazyLoadSetting = {
                isSPA: false,
                preloadRatio: 1,
                processImages: null,
            };
        </script><script>window.addEventListener("load",function(){var t=/\.(gif|jpg|jpeg|tiff|png)$/i,r=/^data:image\/[a-z]+;base64,/;Array.prototype.slice.call(document.querySelectorAll("img[data-original]")).forEach(function(a){var e=a.parentNode;"A"===e.tagName&&(e.href.match(t)||e.href.match(r))&&(e.href=a.dataset.original)})});</script><script>!function(r){r.imageLazyLoadSetting.processImages=t;var e=r.imageLazyLoadSetting.isSPA,n=r.imageLazyLoadSetting.preloadRatio||1,c=a();function a(){var t=Array.prototype.slice.call(document.querySelectorAll("img[data-original]")),e=Array.prototype.slice.call(document.querySelectorAll("[bg-lazy]"));return t.concat(e)}function t(){e&&(c=a());for(var t,o=0;o<c.length;o++)0<=(t=(t=c[o]).getBoundingClientRect()).bottom&&0<=t.left&&t.top<=(r.innerHeight*n||document.documentElement.clientHeight*n)&&function(){var t,e,n,a,i=c[o];e=function(){c=c.filter(function(t){return i!==t}),r.imageLazyLoadSetting.onImageLoaded&&r.imageLazyLoadSetting.onImageLoaded(i)},(t=i).hasAttribute("bg-lazy")?(t.removeAttribute("bg-lazy"),e&&e()):(n=new Image,a=t.getAttribute("data-original"),n.onload=function(){t.src=a,t.removeAttribute("data-original"),e&&e()},t.src!==a&&(n.src=a))}()}function i(){clearTimeout(t.tId),t.tId=setTimeout(t,500)}t(),document.addEventListener("scroll",i),r.addEventListener("resize",i),r.addEventListener("orientationchange",i)}(this);</script></body>
</html>
